//
//  Micro_BusinessCardViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 16/9/22.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Micro_BusinessCardViewController.h"

#import "Edit_BusinessCardViewController.h"

@interface Micro_BusinessCardViewController () <UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView * scrollView;

@property (nonatomic, strong) UIImageView * image_bg;
//
@property (nonatomic, strong) UILabel * lbl_name;
@property (nonatomic, strong) UILabel * lbl_department;
@property (nonatomic, strong) UILabel * lbl_company;
@property (nonatomic, strong) UIImageView * image_heads;
//
@property (nonatomic, strong) UITextView * text_label;
@property (nonatomic, strong) UITextView * text_location;
@property (nonatomic, strong) UILabel * lbl_mail;
@property (nonatomic, strong) UILabel * lbl_tel;

@end

@implementation Micro_BusinessCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"微名片";
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 35, 15)];
    lbl_return.text = @"返回";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 60, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UIImageView * image_share = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 35, 32, 20, 20)];
    image_share.image = [UIImage imageNamed:@"Share_ Omit.png"];
    [_topView addSubview:image_share];
    
    UIButton * btn_share = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_share.frame = CGRectMake(SCREEN_WIDTH - 10 - 35, 24.5, 35, 35);
    [_topView addSubview:btn_share];
    [btn_share addTarget:self action:@selector(btn_shareAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

//右分享
- (void )btn_shareAction:(UIButton *)sender
{
    NSLog(@"右分享到社交平台(友盟)");
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.contentSize = CGSizeMake(0, 0);
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
    self.image_bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.image_bg.image = [UIImage imageNamed:@"5abd76c6a7efce1b9cef4311aa51f3deb68f65f3.jpg"];
    self.image_bg.userInteractionEnabled = YES;
    [self.scrollView addSubview:self.image_bg];
    
    //底下的两个按钮
    [self two_btnDesign];
    
    //标签
    UIImageView * image_label = [[UIImageView alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 120 - 50, 20, 20)];
    image_label.image = [UIImage imageNamed:@"Label.png"];
    [self.image_bg addSubview:image_label];
    
    self.text_label = [[UITextView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_label.frame) + 10, SCREEN_HEIGHT - 120 - 50 - 5, SCREEN_WIDTH - CGRectGetMaxX(image_label.frame) - 40, 45)];
    self.text_label.text = @"标签";
    self.text_label.font = [UIFont systemFontOfSize:15.0f];
    self.text_label.userInteractionEnabled = NO;
    self.text_label.textColor = [UIColor groupTableViewBackgroundColor];
    self.text_label.backgroundColor = [UIColor clearColor];
    [self.image_bg addSubview:self.text_label];
    
    
    //公司地址
    UIImageView * image_location = [[UIImageView alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 170 - 60, 20, 20)];
    image_location.image = [UIImage imageNamed:@"Location.png"];
    [self.image_bg addSubview:image_location];
    
    self.text_location = [[UITextView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_location.frame) + 10, SCREEN_HEIGHT - 170 - 60 - 8, SCREEN_WIDTH - CGRectGetMaxX(image_location.frame) - 40, 62)];
    self.text_location.text = @"公司地址";
    self.text_location.font = [UIFont systemFontOfSize:15.0f];
    self.text_location.userInteractionEnabled = NO;
    self.text_location.textColor = [UIColor groupTableViewBackgroundColor];
    self.text_location.backgroundColor = [UIColor clearColor];
    [self.image_bg addSubview:self.text_location];
    
    //邮箱
    UIImageView * image_mail = [[UIImageView alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 230 - 40, 20, 20)];
    image_mail.image = [UIImage imageNamed:@"Enterprise_mail.png"];
    [self.image_bg addSubview:image_mail];
    
    self.lbl_mail = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_location.frame) + 15, SCREEN_HEIGHT - 230 - 40, SCREEN_WIDTH - CGRectGetMaxX(image_location.frame) - 50, 15)];
    self.lbl_mail.text = @"qwertyuiop.163.com";
    self.lbl_mail.font = [UIFont systemFontOfSize:15.0f];
    self.lbl_mail.textColor = [UIColor groupTableViewBackgroundColor];
    [self.image_bg addSubview:self.lbl_mail];
    
    UIButton * btn_mail = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_mail.frame = CGRectMake(CGRectGetMaxX(image_location.frame) + 15, SCREEN_HEIGHT - 230 - 45, SCREEN_WIDTH - CGRectGetMaxX(image_location.frame) - 50, 35);
    [self.image_bg addSubview:btn_mail];
    [btn_mail addTarget:self action:@selector(btn_mailAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //电话
    UIImageView * image_tel = [[UIImageView alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 270 - 40, 20, 20)];
    image_tel.image = [UIImage imageNamed:@"TEL_Card.png"];
    [self.image_bg addSubview:image_tel];
    
    self.lbl_tel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_tel.frame) + 15, SCREEN_HEIGHT - 270 - 40, SCREEN_WIDTH - CGRectGetMaxX(image_tel.frame) - 50, 15)];
    self.lbl_tel.text = @"1866999XXXX";
    self.lbl_tel.font = [UIFont systemFontOfSize:15.0f];
    self.lbl_tel.textColor = [UIColor groupTableViewBackgroundColor];
    [self.image_bg addSubview:self.lbl_tel];
    
    UIButton * btn_tel = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_tel.frame = CGRectMake(CGRectGetMaxX(image_tel.frame) + 15, SCREEN_HEIGHT - 270 - 40, SCREEN_WIDTH - CGRectGetMaxX(image_tel.frame) - 50, 15);
    [self.image_bg addSubview:btn_tel];
    [btn_tel addTarget:self action:@selector(btn_telAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //公司
    self.lbl_company = [[UILabel alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 310 - 50, SCREEN_WIDTH - 40 - 20, 20)];
    self.lbl_company.text = @"山东智顺网络科技有限公司";
    self.lbl_company.textColor = [UIColor groupTableViewBackgroundColor];
    self.lbl_company.font = [UIFont systemFontOfSize:17.0f];
    self.lbl_company.textAlignment = NSTextAlignmentLeft;
    [self.scrollView addSubview:self.lbl_company];

    //职位
    self.lbl_department = [[UILabel alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 360 - 40, SCREEN_WIDTH - 205, 20)];
    self.lbl_department.text = @"销售经理";
    self.lbl_department.textColor = [UIColor groupTableViewBackgroundColor];
    self.lbl_department.font = [UIFont systemFontOfSize:15.0f];
    self.lbl_department.textAlignment = NSTextAlignmentLeft;
    [self.scrollView addSubview:self.lbl_department];
    
    //姓名
    self.lbl_name = [[UILabel alloc] initWithFrame:CGRectMake(40, SCREEN_HEIGHT - 400 - 40, SCREEN_WIDTH - 205, 30)];
    self.lbl_name.text = @"姓名";
    self.lbl_name.textColor = [UIColor whiteColor];
    self.lbl_name.font = [UIFont systemFontOfSize:23.0f];
    self.lbl_name.textAlignment = NSTextAlignmentLeft;
    [self.scrollView addSubview:self.lbl_name];

    //头像
    self.image_heads = [[UIImageView alloc] init];
    self.image_heads.frame = CGRectMake(SCREEN_WIDTH - 40 - 120, SCREEN_HEIGHT - 440 - 60, 120, 120);
    self.image_heads.layer.cornerRadius = 60;
    if(SCREEN_HEIGHT == 480)
    {
        self.image_heads.frame = CGRectMake(SCREEN_WIDTH - 40 - 100, SCREEN_HEIGHT - 440 - 30, 100, 100);
        self.image_heads.layer.cornerRadius = 50;
    }
    self.image_heads.image = [UIImage imageNamed:@"heads.jpg"];
    self.image_heads.layer.masksToBounds = YES;
    self.image_heads.layer.borderColor = [UIColor whiteColor].CGColor;
    self.image_heads.layer.borderWidth = 2.0f;
    [self.scrollView addSubview:self.image_heads];
}

#pragma mark - 点击版式
- (void )btn_styleAction:(UIButton *)sender
{
    NSLog(@"点击更换版式");
}

#pragma mark - 点击编辑进入编辑页面
- (void )btn_editAction:(UIButton *)sender
{//NSLog(@"点击编辑进入编辑页面");
    Edit_BusinessCardViewController * edit_BusinessCardViewController = [[Edit_BusinessCardViewController alloc] init];
    [self showViewController:edit_BusinessCardViewController sender:nil];
}

#pragma mark - 点击发送邮件
- (void )btn_mailAction:(UIButton *)sender
{//NSLog(@"点击发送邮件");
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://"]];
}

#pragma mark - 点击拨打电话
- (void )btn_telAction:(UIButton *)sender
{//NSLog(@"点击拨打电话");
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"400-8888-888" message:@"" preferredStyle:(UIAlertControllerStyleAlert)];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
    UIAlertAction * action = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action];
    
    UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"拨打" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        NSURL * url_tel = [NSURL URLWithString:[NSString stringWithFormat:@"tel://400-8888-888"]];
        [[UIApplication sharedApplication] openURL:url_tel];
        
    }];
    [alert addAction:action1];
}

#pragma mark - 下面两个btn布局
- (void)two_btnDesign
{
    //下面的两个btn
    CGFloat length_btnX = (SCREEN_WIDTH - 40 * 3) / 2;
    //版式
    UIView * view_style = [[UIView alloc] init];
    view_style.frame = CGRectMake(40, SCREEN_HEIGHT - 84 - 35, length_btnX, 35);
    view_style.layer.cornerRadius = 17;
    if(SCREEN_WIDTH > 350)
    {
        view_style.frame = CGRectMake(40, SCREEN_HEIGHT - 84 - 40, length_btnX, 40);
        view_style.layer.cornerRadius = 18;
    }
    view_style.backgroundColor = [UIColor orangeColor];
    [self.image_bg addSubview:view_style];
    
    UIImageView * image_style = [[UIImageView alloc] init];
    image_style.frame = CGRectMake(length_btnX / 5, (CGRectGetHeight(view_style.frame) - 20) / 2, 20, 20);
    if(SCREEN_WIDTH > 350)
    {
        image_style.frame = CGRectMake(length_btnX / 5, (CGRectGetHeight(view_style.frame) - 25) / 2, 25, 25);
    }
    image_style.image = [UIImage imageNamed:@"style_wihte.png"];
    image_style.layer.masksToBounds = YES;
    [view_style addSubview:image_style];
    
    UILabel * lbl_style = [[UILabel alloc] init];
    lbl_style.frame = CGRectMake(CGRectGetMaxX(image_style.frame) + 5, (CGRectGetHeight(view_style.frame) - 20) / 2, 60, 20);
    lbl_style.font = [UIFont systemFontOfSize:15.0f];
    if(SCREEN_WIDTH > 350)
    {
        lbl_style.frame = CGRectMake(CGRectGetMaxX(image_style.frame) + 10, (CGRectGetHeight(view_style.frame) - 20) / 2, 60, 20);
        lbl_style.font = [UIFont systemFontOfSize:17.0f];
    }
    lbl_style.text = @"版 式";
    lbl_style.textColor = [UIColor whiteColor];
    [view_style addSubview:lbl_style];
    
    UIButton * btn_style = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_style.frame = CGRectMake(0, 0, CGRectGetWidth(view_style.frame), CGRectGetHeight(view_style.frame));
    [view_style addSubview:btn_style];
    [btn_style addTarget:self action:@selector(btn_styleAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //编辑
    UIView * view_edit = [[UIView alloc] init];
    view_edit.frame = CGRectMake(40 + CGRectGetMaxX(view_style.frame), SCREEN_HEIGHT - 84 - 35, length_btnX, 35);
    view_edit.layer.cornerRadius = 17;
    if(SCREEN_WIDTH > 350)
    {
        view_edit.frame = CGRectMake(40 + CGRectGetMaxX(view_style.frame), SCREEN_HEIGHT - 84 - 40, length_btnX, 40);
        view_edit.layer.cornerRadius = 18;
    }
    view_edit.backgroundColor = [UIColor orangeColor];
    [self.image_bg addSubview:view_edit];
    
    UIImageView * image_edit = [[UIImageView alloc] init];
    image_edit.frame = CGRectMake(length_btnX / 5, (CGRectGetHeight(view_edit.frame) - 20) / 2, 20, 20);
    if(SCREEN_WIDTH > 350)
    {
        image_edit.frame = CGRectMake(length_btnX / 5, (CGRectGetHeight(view_edit.frame) - 25) / 2, 25, 25);
    }
    image_edit.image = [UIImage imageNamed:@"edit_wihte.png"];
    image_edit.layer.masksToBounds = YES;
    [view_edit addSubview:image_edit];
    
    UILabel * lbl_edit = [[UILabel alloc] init];
    lbl_edit.frame = CGRectMake(CGRectGetMaxX(image_edit.frame) + 5, (CGRectGetHeight(view_edit.frame) - 20) / 2, 60, 20);
    lbl_edit.font = [UIFont systemFontOfSize:15.0f];
    if(SCREEN_WIDTH > 350)
    {
        lbl_edit.frame = CGRectMake(CGRectGetMaxX(image_edit.frame) + 10, (CGRectGetHeight(view_edit.frame) - 20) / 2, 60, 20);
        lbl_edit.font = [UIFont systemFontOfSize:17.0f];
    }
    lbl_edit.text = @"编 辑";
    lbl_edit.textColor = [UIColor whiteColor];
    [view_edit addSubview:lbl_edit];
    
    UIButton * btn_edit = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_edit.frame = CGRectMake(0, 0, CGRectGetWidth(view_edit.frame), CGRectGetHeight(view_edit.frame));
    [view_edit addSubview:btn_edit];
    [btn_edit addTarget:self action:@selector(btn_editAction:) forControlEvents:(UIControlEventTouchUpInside)];
}


@end
